package com.plus.demo.service;

import java.util.Date;

import org.mybatis.plus.core.SqlSession;
import org.mybatis.plus.core.SqlSessionFactory;
import org.mybatis.plus.core.SqlSessionFactoryBuilder;

import com.plus.demo.mapper.AnswerMapper;
import com.plus.demo.mapper.UserMapper;
import com.plus.demo.po.Answer;
import com.plus.demo.po.User;
public class BizServiceTester {
	
	public static void main(String[] args) throws Exception {
		SqlSessionFactory sqlSessionFactory = SqlSessionFactoryBuilder.build(Thread.currentThread().getContextClassLoader().getResourceAsStream("mybatis.cfg.xml"));
		SqlSession sqlSession=sqlSessionFactory.openSession(sqlSessionFactory.getMybatisCfg());
		try {
			UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
			User user = new User();
			user.setUserId(1);
			user.setUserName("springboot");
			user.setPassword("8284848448");
			user.setPhone("8388448844848");
			userMapper.save(user);
			Answer record = new Answer();
			record.setChoiceId(11);
			record.setEnabled(true);
			record.setQuestionnaireId(22);
			record.setUserId(11);
			record.setVersion(0);
			record.setCreateTime(new Date());
			record.setUpdateTime(new Date());
			AnswerMapper answerMapper = sqlSession.getMapper(AnswerMapper.class);
			answerMapper.insert(record);
			System.out.println(1/0);
			sqlSession.commit();
		} catch (Exception e) {
			e.printStackTrace();
			sqlSession.rollback();
		}finally {
			sqlSession.close();
		}
		
	}
	
}
